package com.jamal2362.apktool.util.aapt2;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import com.jamal2362.apktool.util.as.ASUtils;
import com.jamal2362.apktool.util.search.SearchUtils;

public class fixAll
{
	public static void replace1056to80(File sourceDir)
	{
		File resDir = new File(sourceDir.getAbsolutePath() + "/res");
		if (!resDir.exists())
			return;
		FileFilter dirFilter = new FileFilter() {
			@Override
			public boolean accept(File file)
			{
				return file.isDirectory();
			}
		};
		FilenameFilter xmlFilter = new FilenameFilter() {
			@Override
			public boolean accept(File file, String p2)
			{
				return (p2.equals("strings.xml") || p2.equals("arrays.xml") || p2.equals("plurals.xml"));
			}
		};
		File[] dirs = resDir.listFiles(dirFilter);
		for (File d : dirs)
		{
			File[] files = d.listFiles(xmlFilter);
			if (files == null)
				continue;
			for (File f : files)
			{
				if (!SearchUtils.indexOf(f, "Р", false))
					continue;
				String fstr = ASUtils.readToString(f);
				fstr = ASUtils.replace(fstr, "Р", "P");
				ASUtils.writeToFile(f, fstr);
			}
		}
	}
	
	public static void fixIds(File sourceDir)
	{
		File idsXml = new File(sourceDir.getAbsolutePath() + "/res/values/ids.xml");
		if (!idsXml.exists())
			return;
		String fstr = ASUtils.readToString(idsXml);
		fstr = ASUtils.replace(fstr, ">false</item>", "/>");
		ASUtils.writeToFile(idsXml, fstr);
	}
}
